#{extends 'layout/main.html' /}
#{set title:'Test upload !!!' /}

<link rel="stylesheet" href="/public/javascripts/plugins/plupload/jquery.plupload.queue/css/jquery.plupload.queue.css" type="text/css" media="screen" />

<script type="text/javascript" src="/public/javascripts/plugins/plupload/plupload.js"></script>

<script type="text/javascript" src="/public/javascripts/plugins/plupload/jquery.plupload.queue/jquery.plupload.queue.js"></script>

<script type="text/javascript" src="/public/javascripts/plugins/plupload/plupload.html5.js"></script>
<script type="text/javascript" src="/public/javascripts/plugins/plupload/plupload.gears.js"></script>
 
TEST UPLOAD
<div>
<div id="html5_uploader" style="width: 450px; height: 330px;">You browser doesn't support native upload. Try Firefox 3 or Safari 4.</div>
</div>

<div id="container">
    <div id="filelist">No runtime found.</div>
    <br />
    <a id="pickfiles" href="javascript:;">[Select files]</a> 
    <a id="uploadfiles" href="javascript:;">[Upload files]</a>
</div>

<hr/>
<div>
	<button onclick="upload_click();">Upload</button>
</div>
<script>
	$(function(){
		// Setup html5 version	
		$("#html5_uploader").pluploadQueue({
			// General settings
			runtimes : 'html5',
			url : '/utility/upload',
			max_file_size : '1gb',
			chunk_size : '10mb',
			unique_names : true,
			multi_selection: false,
			filters : [
				{title : "Image files", extensions : "jpg,gif,png"},
				{title : "Zip files", extensions : "zip"}
			],

			// Resize images on clientside if we can
			resize : {width : 320, height : 240, quality : 90}
		});
	});
	
/*********************************/
 
	var uploader = new plupload.Uploader({
		runtimes : 'gears,html5,flash,silverlight,browserplus',
		browse_button : 'pickfiles',
		container: 'container',
		max_file_size : '10mb',
		url : 'upload.php',
		resize : {width : 320, height : 240, quality : 90},
		multi_selection: false,
		filters : [
			{title : "Image files", extensions : "jpg,gif,png"},
			{title : "Zip files", extensions : "zip"}
		]
	});
	
	uploader.bind('Init', function(up, params) {
		document.getElementById('filelist').innerHTML = "<div>Current runtime: " + params.runtime + "</div>";
	});

	uploader.bind('FilesAdded', function(up, files) {
		for (var i in files) {
			document.getElementById('filelist').innerHTML += '<div id="' + files[i].id + '">' + files[i].name + ' (' + plupload.formatSize(files[i].size) + ') <b></b></div>';
		}
	});

	uploader.bind('UploadProgress', function(up, file) {
		document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
	});

	document.getElementById('uploadfiles').onclick = function() {
		uploader.start();
		return false;
	};

	uploader.init();
		
	function upload_click(){
		$('#file_upload').uploadify('upload','*');
	}
</script>

